<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .active {
        color: red;
      }
    </style>
  </head>
  <body>
    <div class="active">sw</div>
    <div>申伟</div>
    <div>jhk</div>
    <div>sw</div>
    <div>申伟</div>
    <div>sw</div>
    <div>申伟</div>
    <div>sw</div>
    <div>申伟</div>
    <div>sw</div>
  </body>
  <script>
    const divs = document.querySelectorAll("div");
    for (let i = 0; i < divs.length; i++) {
      divs[i].addEventListener("click", function () {
        document.querySelector(".active").className = "";
        this.className = "active";
      });
    }
  </script>
</html>
